package com.baosight.scaq.aq.ci.service; 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.scaq.aq.ci.domain.AQCIEquipmentInfo;
import com.baosight.scaq.aq.ci.domain.AQCIPersonInfo;
import com.baosight.scaq.aq.ci.domain.AQCIRealtimePersonInfo;
import com.baosight.scaq.common.aq.basetools.StaticTools;

/**
 * 
 * <p>Title: ServiceAQCI10.java</p>
 * <p>Description: 生产运营监视——井下人员</p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 郭淑芳
 * @version 1.0
 * <pre>Histroy:
 *          2016年4月8日 下午3:00:08  郭淑芳  Create
 *</pre>
 */
public class ServiceAQCI10 extends ServiceEPBase {

	/**
	 * 
	 * <p>Function: initLoad</p>
	 * <p>Description: 初始化</p>
	 * <p>return value: ServiceAQCI10</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年4月8日下午2:59:54 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");// 如果不加这个，翻页的统计和显示是错误的
		inInfo = this.query(inInfo);
		return inInfo;
	}
	
	/**
	 * 
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceAQCI10</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年4月8日下午3:02:20 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
//	//	String fdMineId = inInfo.getString("fdMineId").trim();
//		String fdMineId = UserSession.getInSessionProperty("miningCode").toString();
//		EiInfo outInfo = new EiInfo();
//
//		// 判断所选中节点是否集团
//		if (fdMineId.equals("defaultOrg")) {
//		
//			AQCIPersonInfo _dom = new AQCIPersonInfo();
//			EiBlock eiBlock = inInfo.getBlock("result");
//			eiBlock.setBlockMeta(_dom.eiMetadata);
//			
//			// 获取下属各矿信息
//			List<Map> list = new ArrayList();
//			Map<String, String> _argMap = new HashMap<String, String>();
//			list = dao.query("ZM02.queryTreeChild", _argMap);
//
//			// 查询各矿人员信息
//			List<AQCIPersonInfo> infoList = new ArrayList();
//			for (int i = 0; i < list.size(); i++) {
//				Map<String, String> _orgMap = new HashMap<String, String>();
//				_orgMap.put("fdMiningId", list.get(i).get("label").toString());
//				infoList = dao.query("AQCIPersonInfo.query",_orgMap);
//				eiBlock.addRows(infoList);
//			}
//			outInfo.addBlock(eiBlock);
//		} else {
//			String date = StaticTools.getDate();
//			StaticTools.setQueryParameters(inInfo, "fdLocationTime", date, false);// 添加查询条件
//			StaticTools.setQueryParameters(inInfo, "fdMiningId", fdMineId, true);// 添加查询条件
//			outInfo = super.query(inInfo, "AQCIPersonInfo.query", new AQCIPersonInfo());
//		}
		EiInfo outInfo = super.query(inInfo, "AQCIRealtimePersonInfo.query", new AQCIRealtimePersonInfo());
		outInfo.addBlock(getMines());
		return outInfo;
	}

	/**
	 * 矿井block
	 * @return
	 */
	private EiBlock getMines() {
		// TODO Auto-generated method stub
		EiBlock block = new EiBlock("cmes.ch.mine");

		EiColumn EiColumn = new EiColumn("display");
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		EiColumn = new EiColumn("value");
		EiColumn.setType("C");
		block.addMeta(EiColumn);

		List<Map> _list = new ArrayList<Map>();
		Map<String, String> _map = new HashMap<String, String>();
		_map.put("value", "");
		_map.put("display", "");
		_list.add(_map);

		List<Map> _listData = new ArrayList<Map>();
		try {
			_listData = dao.query("AQCIEquipmentInfo.queryTreeChild", null);
		} catch (Exception e) {}
		
		for(int i = 0; i < _listData.size(); i++) {
			_list.add(_listData.get(i)); 
		} 
		block.setRows(_list);
		return block;
	}

}
